#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, m;
	cin >> n >> m;

	vector<vector<int>> gh(n + 1);
	vector<int> indgree(n + 1, 0);
	vector<int> lines(n + 1, 0);

	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		gh[u].push_back(v);
		indgree[v]++;
	}

	queue<int> q;
	for (int i = 1; i < indgree.size(); i++) {
		if (indgree[i] == 0) {
			q.push(i);
			lines[i] = 1;
		}
	}

	int ans = 0;
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		if (gh[u].size() == 0) {
			ans = (lines[u] + ans) % 80112002;
		}
		for (auto v : gh[u]) {
			lines[v] = (lines[u] + lines[v]) % 80112002;
			if (--indgree[v] == 0) {
				q.push(v);
			}
		}
	}
	cout << ans << endl;
	return 0;
}